<?php 

session_start();

require_once "lib/model.inc";
require_once "lib/template.inc";

$stash[current_login] = $_SESSION[current_login];

if ($stash[current_login]) {
    $stash[show_add_form] = 1;
} else {
    $stash[auth_required] = 1;
    return get_template("event_results", $stash);
}

if ($_GET['event_id']) {
        $stash[show_form] = 1;

        /* 10 files to upload */
	for ($i = 0; $i < 10; $i++) {
            $target_path = "images/";

            if($tmp_name = $_FILES["image$i"]['tmp_name']) {
		$uniq_image_name = get_uuid();
	        /* Add the original filename to our target path.  
        	Result is "uploads/filename.extension" */
        	$target_path = $target_path . $uniq_image_name;  //basename( $_FILES["image$i"]['name']); 

                if (move_uploaded_file($tmp_name, $target_path )) {
                    echo "uploaded ok";
	            add_image($uniq_image_name, $_GET['event_id']);
                } else {
                    echo "upload eerrorr!!";
                }
        } 
    }
} else {
    $stash["show_error"] = 1;
}

    echo get_template("add_images", $stash);  
?>
